package com.example.myapplication.ui.upload

import androidx.room.ColumnInfo
import androidx.room.Entity
import com.example.myapplication.utils.DiffUIDataUtil
import com.example.myapplication.ui.FileBean
import java.util.*
/**
 * 文件上传表
 */
@Entity(tableName = "file_upload_table")
class FileUploadBean : FileBean, DiffUIDataUtil.UiDataDiffer<FileUploadBean> {

    companion object {
        const val UPLOAD_READY: Byte = 3
        const val UPLOAD_RUNNING: Byte = 1
        const val UPLOAD_ERROR: Byte = 2
        const val UPLOAD_FINISH: Byte = 4
    }

    @ColumnInfo(name = "uploadId")
    var uploadId: String? = null

    @ColumnInfo(name = "uploadSize")
    var uploadSize: Long = 0

    @ColumnInfo(name = "chunkNumber")
    var chunkNumber: Int? = null

    @ColumnInfo(name = "uploadState")
    var uploadState: Byte = UPLOAD_READY

    @ColumnInfo(name = "uploadSpeed")
    var uploadSpeed: Long = 0

    constructor() : this(UUID.randomUUID().toString())
    constructor(idx: String) : super(idx)

    override fun toString(): String {
        return " ${super.toString()} uploadId=$uploadId,  uploadSize=$uploadSize, chunkNumber=$chunkNumber,  uploadState=$uploadState"
    }

    override fun isSame(old: FileUploadBean): Boolean {
        return this.id.equals(old.id)
    }

    override fun isUiContentSame(old: FileUploadBean): Boolean {
        return this.deleted == this.deleted &&
                this.enabled == old.enabled &&
                this.uploadSize == old.uploadSize &&
                this.uploadState == old.uploadState &&
                this.uploadId.equals(old.uploadId)&&
                this.state.equals(old.state)

    }

}